package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Goods;
import service.GoodsManager;
import service.impl.GoodsManagerFactory;

/**
 * Servlet implementation class ShowGoodsServlet
 */
public class ShowGoodsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private GoodsManager manager;   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowGoodsServlet() {
        super();
        manager = GoodsManagerFactory.getInstance();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String address = (String) request.getAttribute("address");
		if(address==null){
			address = request.getParameter("address");
		}
		List<Goods> goodsList = manager.loadAllByAdress(address);
		request.setAttribute("goodsList", goodsList);
		request.setAttribute("address", address);
		request.getRequestDispatcher("showList.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
